#include "cpuHc32f460.h"
#include "system_hc32f460.h"
#include "stdbool.h"
void InitGPIO(port_init_t *TGPIOALL_Config, int GPIOSize)
{
	uint8_t i;
	
    LL_PERIPH_WE(LL_PERIPH_GPIO);
	GPIO_SetDebugPort(GPIO_PIN_SWO, false);
	GPIO_SetDebugPort(GPIO_PIN_TRST, false);
	GPIO_SetDebugPort(GPIO_PIN_TDI, false);
    
	for(i = 0; i < GPIOSize; i++)
	{
        CLEAR_WATCH_DOG;  
		if(TGPIOALL_Config[i].FuncReg != GPIO_DEFAULT)
		{
			GPIO_Init(TGPIOALL_Config[i].enPort,TGPIOALL_Config[i].u16Pin,&TGPIOALL_Config[i].GpioReg);
			if(TGPIOALL_Config[i].GpioReg.u16PinDir == PIN_DIR_OUT)	
			{
				if(TGPIOALL_Config[i].GpioReg.u16PinState == HIGH)
				{
					GPIO_SetPins(TGPIOALL_Config[i].enPort,TGPIOALL_Config[i].u16Pin);
				}
				else if(TGPIOALL_Config[i].GpioReg.u16PinState == LOW)
				{
					GPIO_ResetPins(TGPIOALL_Config[i].enPort,TGPIOALL_Config[i].u16Pin);
				}
				else
				{
					
				}
			}			
			if(TGPIOALL_Config[i].FuncReg != GPIO_FUNC_0)
			{
				GPIO_SetFunc(TGPIOALL_Config[i].enPort,TGPIOALL_Config[i].u16Pin,TGPIOALL_Config[i].FuncReg);
			}
		}
	}
    LL_PERIPH_WP(LL_PERIPH_GPIO);
}
